package com.bing.services.impl;

import com.bing.bean.weixin.User;
import com.bing.dao.AccountUserDao;
import com.bing.dao.UserDao;
import com.bing.services.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by Administrator on 2014/12/28.
 */
@Service
@Transactional
public class UserImpl implements UserService {

    @Autowired
    private UserDao userDao;

    @Autowired
    private AccountUserDao accountUserDao;

    /**
     * 查询用户,如不存在则创建
     *
     * @param user
     * @return
     */
    @Override
    public User getUser(User user) {
        User nuser = userDao.findByOidAndType(user);
        if (nuser == null) {
            userDao.create(user);
            accountUserDao.create(user.getAccount().getId(),user.getId());
            nuser = user;
        }
        return nuser;
    }

    @Override
    public void updateUser(User user) {
        userDao.update(user);
    }

}
